var express = require('express');
var router = express.Router();
let fs = require('fs')

// 设置允许跨域请求
router.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers" , "Origin, X-Requested-With, Content-Type, Accept");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By",' 3.2.1')
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});


/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/getList',(req,res) => {
  // res.send("halo")
  // console.log(__dirname)
  fs.readFile(__dirname+'/list.json',(err,data)=>{
    if(!err){
      let str = data.toString();
      let json = JSON.parse(str)
      
      res.json(json)
    }
  });
})

router.get('/getsongs',(req,res)=> {
  fs.readFile(__dirname+'/songs2.json',(err,data)=>{
    if(!err){
      let str = data.toString();
      let json = JSON.parse(str)
      
      res.json(json)
    }
  });
})



module.exports = router;
